home *** CD-ROM | disk | FTP | other *** search
Wrap
// PSsWizard.cpp : Implementation of CPSsWizard #include "stdafx.h" #include "TCPssWiz.h" #include "PSsWizard.h" #include "PaperSpaceWizard.h" #include "xdbtool_i.c" #include "imsigx_i.c" #include "gxmps_i.c" ///////////////////////////////////////////////////////////////////////////// // CPSsWizard COleVariant t(-1L, VT_BOOL); COleVariant f(0L, VT_BOOL); COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR); ///////////////////////////////////////////////////////////////////////////// STDMETHODIMP CPSsWizard::get_ClassID(BSTR *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) HRESULT hRes = E_FAIL; LPOLESTR olestr = NULL; try { if(SUCCEEDED( ::StringFromCLSID(CLSID_PSsWizard, &olestr))) { *pVal = ::SysAllocString(olestr); hRes = S_OK; } } catch (...) { TRACE_EXCEPTION("CPSsWizard::get_ClassID") } if (olestr != NULL) CoTaskMemFree(olestr); return hRes; } STDMETHODIMP CPSsWizard::get_Description(BSTR *pVal) { // Get the description from the resource HRESULT hRes = E_FAIL; CString strResult; if (strResult.LoadString(IDS_DESCRIPTION)) { *pVal = strResult.AllocSysString(); hRes = S_OK; } return hRes; } STDMETHODIMP CPSsWizard::GetToolInfo(VARIANT *CommandNames, VARIANT *MenuCaptions, VARIANT *StatusPrompts, VARIANT *ToolTips, VARIANT *Enabled, VARIANT *WantsUpdates, long *ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) HRESULT hRes = E_FAIL; SAFEARRAYBOUND bound = {NUM_TOOLS, 0}; CString cstrText; CString cstrTextTemp; BSTR bstrCommandName = NULL; BSTR bstrMenuCaption = NULL; BSTR bstrStatusPrompt = NULL; BSTR bstrToolTip = NULL; BOOL bEnabled = TRUE; BOOL bWantsUpdates = TRUE; long lIndicies = 0; try { hRes = SafeArrayRedim(CommandNames->parray, &bound); CHECK_HRESULT(hRes) hRes = SafeArrayRedim(MenuCaptions->parray, &bound); CHECK_HRESULT(hRes) hRes = SafeArrayRedim(StatusPrompts->parray, &bound); CHECK_HRESULT(hRes) hRes = SafeArrayRedim(ToolTips->parray, &bound); CHECK_HRESULT(hRes) hRes = SafeArrayRedim(Enabled->parray, &bound); CHECK_HRESULT(hRes) hRes = SafeArrayRedim(WantsUpdates->parray, &bound); CHECK_HRESULT(hRes) // AALB 141199 CString cstrText="Insert|Dimension|Tolerance"; cstrText.LoadString (IDS_MAINMENU); cstrText.Insert(cstrText.GetLength (), '|'); cstrTextTemp.LoadString (IDS_SUBMENU); cstrText.Insert(cstrText.GetLength (), cstrTextTemp); cstrText.Insert(cstrText.GetLength (), '|'); cstrTextTemp.LoadString (IDS_MENUCAPTION); cstrText.Insert(cstrText.GetLength (), cstrTextTemp); cstrTextTemp.Empty (); bstrCommandName = cstrText.AllocSysString(); hRes = SafeArrayPutElement(CommandNames->parray, &lIndicies, (void *)bstrCommandName); CHECK_HRESULT(hRes) cstrText.Empty (); // AALB 141199 move this string to resource cstrText="Tolerance"; cstrText.LoadString (IDS_MENUCAPTION); bstrMenuCaption = cstrText.AllocSysString(); hRes = SafeArrayPutElement(MenuCaptions->parray, &lIndicies, (void *)bstrMenuCaption); CHECK_HRESULT(hRes) cstrText.Empty (); cstrText.LoadString (IDS_PROMT0); bstrStatusPrompt = cstrText.AllocSysString(); hRes = SafeArrayPutElement(StatusPrompts->parray, &lIndicies, (void *)bstrStatusPrompt); CHECK_HRESULT(hRes) cstrText.Empty (); // AALB 141199 cstrText="Insert tolerance symbol"; cstrText.LoadString (IDS_TOOLTIPS);; bstrToolTip = cstrText.AllocSysString(); hRes = SafeArrayPutElement(ToolTips->parray, &lIndicies, (void *)bstrToolTip); CHECK_HRESULT(hRes) hRes = SafeArrayPutElement(Enabled->parray, &lIndicies, (void *)&bEnabled); CHECK_HRESULT(hRes) hRes = SafeArrayPutElement(WantsUpdates->parray, &lIndicies, (void *)&bWantsUpdates); CHECK_HRESULT(hRes) *ret = NUM_TOOLS; } catch (...) { if (SUCCEEDED(hRes)) hRes = E_FAIL; TRACE_EXCEPTION("CPSsWizard::GetToolInfo") } return hRes; } STDMETHODIMP CPSsWizard::GetPicture(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, IDispatch **ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) LPTSTR IDB = 0; HRESULT hRes = E_FAIL; // CBitmap pBmp; try { // pBmp.LoadBitmap (IDB_BMP1); if(LargeButtons) { IDB = MAKEINTRESOURCE(IDB_BMP2); } else { IDB = MAKEINTRESOURCE(IDB_BMP1); } HBITMAP pBmp = ::LoadBitmap(AfxGetResourceHandle(), IDB); PICTDESC pict; pict.cbSizeofstruct = sizeof(pict); pict.picType = PICTYPE_BITMAP; pict.bmp.hbitmap = pBmp; pict.bmp.hpal = NULL; hRes = OleCreatePictureIndirect(&pict, IID_IDispatch, TRUE, (void**)ret); CHECK_HRESULT(hRes) hRes = S_OK; } catch (...) { TRACE_EXCEPTION("CPSsWizard::GetPicture") } return hRes; } STDMETHODIMP CPSsWizard::CopyBitmap(VARIANT_BOOL LargeButtons, VARIANT_BOOL Monochrome, VARIANT_BOOL *ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::UpdateToolStatus(IDispatch *ThisTool, VARIANT_BOOL *Enabled, VARIANT_BOOL *Checked, VARIANT_BOOL *ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::Initialize(IDispatch *ThisTool, VARIANT_BOOL *ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::Terminate(IDispatch *ThisTool) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::Run(IDispatch *ThisTool, VARIANT_BOOL *ret) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) HRESULT hRes = E_FAIL; Tool *pTool = NULL; IApplication *pIApp = NULL; Graphics* pGrs = NULL; IDrawing *pDr = NULL; long lPsscount = 0; COleVariant varAperture(0.2); COleVariant varOptional(varMissing); COleVariant varType((const long)imsiPolyline); COleVariant varItem = (0L); PaperSpaces *pPss = NULL; CString cstrText; BSTR bstrStatusPrompt; cstrText.LoadString (IDS_PROMT); bstrStatusPrompt = cstrText.AllocSysString(); m_bDragging = FALSE; // COleVariant varType((const long)imsiGroup); COleVariant varProp; Properties *pProps = NULL; Property *pProp = NULL; IDispatch *pIDisp = NULL; PAPERSPACEINFO pPSInfo; PaperSpace *pPs = NULL; IDispatch *pDisp = NULL; if(m_bRunned) return S_OK; try { hRes = ThisTool->QueryInterface(IID_Tool, (void **)&m_pTool); CHECK_HRESULT(hRes) hRes = m_pTool->get_Application(&m_pIApplication); CHECK_HRESULT(hRes) hRes = QueryInterface(IID_IPSsWizard, (void**)&m_pITool); CHECK_HRESULT(hRes) hRes = m_pIApplication->get_ActiveDrawing(&pDr); CHECK_HRESULT(hRes) hRes = pDr->get_PaperSpaces(&pIDisp); CHECK_HRESULT(hRes); hRes = pIDisp->QueryInterface (IID_PaperSpaces,(void**)&pPss); CHECK_HRESULT(hRes); hRes = pPss->get_Count(&lPsscount); CHECK_HRESULT(hRes) CString cstrTextTemp; char v[10]; memset(v, 0, 10); lPsscount++; _ltoa(lPsscount,v, 10); lPsscount--; // AfxMessageBox("PaperSpace wizard tool is runned."); CPaperSpaceWizard dlg(IDS_DESCRIPTION,NULL, 0); // CString cstrWizCaption; cstrText.LoadString (IDS_PSNAMETEMPLATE); // cstrTextTemp = " - Begin"; cstrText.Insert((cstrText.GetLength ()), " "); cstrText.Insert((cstrText.GetLength ()), v); dlg.m_PSInfo = & pPSInfo; dlg.m_pPss = pPss; dlg.m_pPss->AddRef(); dlg.m_PSInfo->bPaperOrientation = 0; dlg.m_PSInfo->cstrPSpaceName = cstrText; int nResponse = dlg.DoModal(); nResponse = IDOK; if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK BSTR bstrPsName; bstrPsName = pPSInfo.cstrPSpaceName.AllocSysString (); /* hRes = pPss->Add(bstrPsName, &pDisp); CHECK_HRESULT(hRes) hRes = pDisp->QueryInterface (IID_PaperSpace, (void**)&pPs); CHECK_HRESULT(hRes) hRes = pPs->Activate(); CHECK_HRESULT(hRes) */ } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } /* hRes = ThisTool->QueryInterface(IID_Tool, (void **)&m_pTool); CHECK_HRESULT(hRes) hRes = m_pTool->get_Application(&m_pIApplication); CHECK_HRESULT(hRes) hRes = QueryInterface(IID_IPSsWizard, (void**)&m_pITool); CHECK_HRESULT(hRes) hRes = m_pIApplication->QueryInterface(IID_IToolEvents, (void **)&m_pIToolEvents); CHECK_HRESULT(hRes) hRes = m_pIToolEvents->ToolChangePrompt(m_pITool,bstrStatusPrompt , FALSE); CHECK_HRESULT(hRes) */ } catch (...) { TRACE_EXCEPTION("CPSsWizard::Run") } RELEASE(pPs) RELEASE(pDisp) RELEASE(pPss); RELEASE(pDr); RELEASE(m_pIApplication); return S_OK; } STDMETHODIMP CPSsWizard::MouseDown(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::MouseUp(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, short Button, long Shift, long X, long Y, VARIANT_BOOL *Cancel) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::MouseMove(IDispatch *WhichDrawing, IDispatch *WhichView, IDispatch *WhichWindow, long Shift, long X, long Y, VARIANT_BOOL *pbCancel) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } STDMETHODIMP CPSsWizard::RunTool(IDispatch *ThisTool) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here return S_OK; } void CPSsWizard::ConnectEvents(IDispatch *ThisTool) { HRESULT hRes = S_OK; if (m_dwEventConnection != 0) { // AfxMessageBox("Already connected."); return; } try { DWORD dwEventMask = imsiEventMouseUp // | imsiEventSelectionChange | imsiEventMouseMove | imsiEventMouseDown | imsiEventDrawingDeactivate | imsiEventRunTool | imsiEventBeforeExit; // | imsiEventMouseMove; // | imsiEventPointSnapped; COleVariant var((long)dwEventMask); hRes = m_pIApplication->ConnectEvents(ThisTool, &var, (long*)&m_dwEventConnection); if (FAILED(hRes)) { // AfxMessageBox("Connection not established."); return; } } catch (...) { TRACE_EXCEPTION("CPSsWizard::ConnectEvents") } } void CPSsWizard::DisconnectEvents() { if (m_pIApplication == NULL || m_dwEventConnection == 0) return; try { HRESULT hRes = m_pIApplication->DisconnectEvents(m_dwEventConnection); CHECK_HRESULT(hRes) if (FAILED(hRes)) { // AfxMessageBox("Connection not broken."); return; } m_dwEventConnection = 0; } catch (...) { TRACE_EXCEPTION("CPSsWizard::DisconnectEvents") } // if(m_pIApplication != NULL) // { // m_pIApplication->Release(); // m_pIApplication = NULL; // } } void CPSsWizard::Destroy() { // RELEASE(m_pView) CString cstrT; cstrT.Empty (); BSTR bstrPromt = NULL; bstrPromt = cstrT.AllocSysString (); m_pIToolEvents->ToolChangePrompt(m_pITool,bstrPromt, FALSE); RELEASE(m_pIToolEvents) DisconnectEvents(); RELEASE(m_pDragGraphic); RELEASE(m_pITool); RELEASE(m_pTool); RELEASE(m_pIApplication); m_bRunned = FALSE; }